//
//  LSZBasicDataViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/10/27.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZBasicDataViewController.h"

@interface LSZBasicDataViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewBasicData;
@property(nonatomic,strong) LSZCommunicationDataManager * communicationDataManager;
@end

@implementation LSZBasicDataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"基础数据";
    [self.tableViewBasicData registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    if ([NullStringjudgment(NSStr(self.branchId)) isEqualToString:@""]) {
        [self getDataBasucData];
    }else{
        [self secondaryData];
    }
}
-(void)getDataBasucData
{
    [LSZRequestDicData getMyOrganization:^(BOOL isOK, NSString * string, LSZCommunicationDataManager * communicationDataManager) {
        if (isOK == YES) {
            self.communicationDataManager = communicationDataManager;
            [self.tableViewBasicData reloadData];
        }else{
            
        }
    }];
}
-(void)secondaryData
{
    [LSZRequestDicData initBranchAcquisition:self.branchId :^(BOOL isOK, NSString * string, LSZCommunicationDataManager * communicationDataManager) {
        if (isOK == YES) {
            self.communicationDataManager = communicationDataManager;
            [self.tableViewBasicData reloadData];
        }else{
            
        }
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.communicationDataManager.arrayData.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    if (self.communicationDataManager.arrayData.count >indexPath.row) {
        LSZCommunicationDataMg * mg = nil;
        mg = self.communicationDataManager.arrayData[indexPath.row];
        cell.textLabel.text = [NSString stringWithFormat:@"%@",mg.name];
    }
    cell.textLabel.textColor = titleColorLSZ;
    cell.textLabel.font = FONT_(14);
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.communicationDataManager.arrayData.count > indexPath.row) {
        LSZCommunicationDataMg * mg = nil;
        mg = self.communicationDataManager.arrayData[indexPath.row];
        if ([mg.leaf isEqualToString:@"false"]) {
            LSZBasicDataViewController * vc = [[LSZBasicDataViewController alloc]init];
            vc.branchId = mg.id_id;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [LSZRequestDicData getThePoorHouseholdsBelowTheVillage:mg.id_id :^(BOOL isOK, NSString * string, LSZInquiryPoorHouseholdsManager * inquiryPoorHouseholdsManager) {
                if (isOK == YES) {
                    LSZPoorHouseholdViewController * VC = [[LSZPoorHouseholdViewController alloc]init];
                    VC.inquiryPoorHouseholdsManager = inquiryPoorHouseholdsManager;
                    [self.navigationController pushViewController:VC animated:YES];
                }else{
                    [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
                }
            }];
     
        }
    }
}
-(UITableView *)tableViewBasicData
{
    if (_tableViewBasicData == nil) {
        _tableViewBasicData = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height) style:UITableViewStylePlain];
        _tableViewBasicData.delegate = self;
        _tableViewBasicData.dataSource = self;
        _tableViewBasicData.estimatedRowHeight=0;
        _tableViewBasicData.estimatedSectionFooterHeight =0;
        _tableViewBasicData.estimatedSectionHeaderHeight =0;
        [_tableViewBasicData setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewBasicData];
    }
    return _tableViewBasicData;
}


@end
